package core.query.filter;

import java.io.Serializable;

public class ISqlFilter implements Serializable {

	private static final long serialVersionUID = -1131610520721362504L;

	private String keyword;

	private Object filterValue;

	private String operator = "=";

	public ISqlFilter(String keyword, Object filterValue) {
		this.keyword = keyword;
		this.filterValue = filterValue;
	}
	
	public void setOperator(String operator) {
		this.operator = operator;
	}

	public String getKeyword() {
		return keyword;
	}

	public Object getFilterValue() {
		return filterValue;
	}

	public String getOperator() {
		return operator;
	}

	public String getValue() {
		return transfer(filterValue.toString());
	}

	public static String transfer(String keyword) {
		if (keyword.contains("%") || keyword.contains("_")) {
			keyword = keyword.replaceAll("\\\\", "\\\\\\\\")
					.replaceAll("\\%", "\\\\%").replaceAll("\\_", "\\\\_");
		}
		return keyword;
	}

}
